package cn.myblog.ainblog.conroller;

import cn.myblog.ainblog.model.CategoryModel;
import cn.myblog.ainblog.service.ArticleService;
import cn.myblog.ainblog.service.CategoryService;
import cn.myblog.ainblog.vo.ArticleCategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author Dovaior
 * @Description 子分类的控制器
 * @create 2021-05-04 15:34
 **/
@Controller
public class CategorySubController {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private ArticleService articleService;

    /**
     * 分类子页面的显示
     * @param categoryId 指定博文的id
     * @param model 封装信息的载体
     * @return 返回信息给前端
     */
    @GetMapping("/category_subpage/{categoryId}")
    public String categorySubpage(@PathVariable String categoryId, Model model){
        //封装指定id的分类信息
        model.addAttribute("categoryModel",categoryService.selectById(categoryId));
        //封装同分类的全部博文
        model.addAttribute("articleCategoryVOS",articleService.queryArticleModelByCategoryToSubPage(categoryId));
        return "category-subpage";
    }

}
